
package Controller;

import com.mysql.jdbc.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class Mes {
    public static Statement st ;
    public static ResultSet rs;
    private static ResultSet rs1;
    public static int id;
    
    
    public static ResultSet filtrarVentas() throws SQLException{
    st = Controller.Conexion.conectar();
    rs = st.executeQuery("select mes,anio,egreso,ingreso_efectivo,ingreso_tarjeta from mensual");
    
    return rs;
    }
    
    public static void cargarTabla(int anio,String mes, float totalEfectivo, float totalTarjeta, float gasto) throws SQLException{
    
            st = Controller.Conexion.conectar();
            rs= st.executeQuery("SELECT id FROM mensual");
            if (rs != null && rs.next()) {
            
                rs1 = st.executeQuery("SELECT max(id) FROM mensual"/*
                         * "SELECT id FROM ventas ORDER BY 'id' DESC LIMIT 1"*/
                         );
                while (rs1.next()) {
                    id = ((Integer) rs1.getObject(1)) + 1;
                   
                }
                
                
                    
                    Statement st2 = (Statement) Controller.Conexion.conectar();
                    st2.executeUpdate("INSERT INTO mensual (id, anio, ingreso_efectivo, ingreso_tarjeta, egreso,mes) VALUES (" + id + ",'" + anio + "'," + totalEfectivo + ","+totalTarjeta+ "," + gasto+ ",'" + mes+"')");
                  

            } else {
                
              
                    
                    Statement st1 = (Statement) Controller.Conexion.conectar();
                    st1.executeUpdate("INSERT INTO mensual (id, anio, ingreso_efectivo, ingreso_tarjeta, egreso,mes) VALUES (" + 1  + ",'" + anio + "'," + totalEfectivo +  ","+totalTarjeta + "," + gasto + ",'" + mes+"')");
                    
                    
                }
    
    }
}
